#pragma once
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include <map>

#define BL_SHM_ID			0x5abc
#define	BL_BUF_SIZE			1024
#define	BL_LIGHT_ADDR		0x00

using namespace std;
//#define HWDAEMON_DEV "/proc/hwDaemon_config"

//INI文件结点存储结构
class ININode
{
public:
	ININode(string root, string key, string value)
	{
		this->root = root;
		this->key = key;
		this->value = value;
	}
	string root;
	string key;
	string value;
};

//键值对结构体
class SubNode
{
public:
	void InsertElement(string key, string value)
	{
		sub_node.insert(pair<string, string>(key, value));
	}
	map<string, string> sub_node;
};

class CShareMemory;

//INI文件操作类
class IniFile
{
public:
	IniFile();
	//int ReadBrightness();		//旧版读驱动中设置的LVDS值
	~IniFile();

	string GetValue(string root, string key);									//由根结点和键获取值
	vector<ININode>::size_type GetSize(){ return map_ini.size(); }				//获取INI文件的结点数
	vector<ININode>::size_type SetValue(string root, string key, string value);	//设置根结点和键获取值
	int ReadBrightness();				//读取系统背光亮度
	int WriteINI();						//写入INI文件
	void Clear(){ map_ini.clear(); }	//清空
	void Travel();						//遍历打印INI文件
	void SetBrightness(int cur);
	bool SetBrightnessUP();
	bool SetBrightnessDown();
	int  GetCurBrightnessIndex();
	void SwitchLightON(bool isOn);
	bool LvdsIsEnabled();
	void initLater();
	void IncKeyCounts(int key_types);
private:
	//int config_fd;
	unsigned int key_counts[6];			//记录按键按下的次数, 0-5对应为6个按键
	int maxBrightness;
	int minBrightness;
	int curBrightness;
	// 共享内存相关
	CShareMemory *shareMemory;
	map<string, SubNode> map_ini;		//INI文件内容的存储变量
	int ReadINI(string path);			//读取INI文件, 在开始的时候读取
	void brightnessIndexInit();
};

